package pl.un4giv3n.mightvsmagic.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Embeddable;
import javax.persistence.Embedded;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;

@Embeddable
public class Action implements Serializable {
	private static final long serialVersionUID = 1L;
	/**
	 * action type
	 */
	@Enumerated(EnumType.STRING)
	private ActionType actionType;
	/**
	 * action start time
	 */
	private Date started;
	/**
	 * action reward
	 */
	@Embedded
	private Reward reward;

	/**
	 * this is a Null Item pattern object
	 */
	public transient static Action NO_ACTION;

	static {
		NO_ACTION = new Action(ActionType.NO_ACTION, Reward.NO_REWARD);
		NO_ACTION.setStarted(new Date(0));
	}

	@SuppressWarnings("unused")
	private Action() {
	}

	public Action(ActionType type, Reward reward) {
		this.actionType = type;
		started = new Date();
		this.reward = reward;
	}

	public ActionType getActionType() {
		return actionType;
	}

	public void setActionType(ActionType actionType) {
		this.actionType = actionType;
	}

	public Date getStarted() {
		return started;
	}

	public void setStarted(Date started) {
		this.started = started;
	}

	public Reward getReward() {
		return reward;
	}

	public void setReward(Reward reward) {
		this.reward = reward;
	}

	@Override
	public String toString() {
		return "Action type=" + actionType + " started " + started;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((actionType == null) ? 0 : actionType.hashCode());
		result = prime * result + ((started == null) ? 0 : started.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		Action other = (Action) obj;
		if (actionType == null) {
			if (other.actionType != null) {
				return false;
			}
		} else if (actionType.equals(ActionType.NO_ACTION)) {
			return true;
		}
		if (!actionType.equals(other.actionType)) {
			return false;
		}
		if (started == null) {
			if (other.started != null)
				return false;
		} else if (!started.equals(other.started))
			return false;
		return true;
	}

}
